home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Unix / gopher1.12 / gopherd / NeXTindex.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-21  |  3.4 KB  |  140 lines

  1. /********************************************************************
  2.  * $Author: lindner $
  3.  * $Revision: 1.1 $
  4.  * $Date: 1992/12/10 23:13:27 $
  5.  * $Source: /home/mudhoney/GopherSrc/release1.11/gopherd/RCS/NeXTindex.c,v $
  6.  * $Status: $
  7.  *
  8.  * Paul Lindner, University of Minnesota CIS.
  9.  *
  10.  * Copyright 1991, 1992 by the Regents of the University of Minnesota
  11.  * see the file "Copyright" in the distribution for conditions of use.
  12.  *********************************************************************
  13.  * MODULE: NeXTindex.c
  14.  * index interface to the NeXT text indexing routines. 
  15.  *********************************************************************
  16.  * Revision History:
  17.  * $Log: NeXTindex.c,v $
  18.  * Revision 1.1  1992/12/10  23:13:27  lindner
  19.  * gopher 1.1 release
  20.  *
  21.  *
  22.  *********************************************************************/
  23.  
  24. #include <sys/stat.h>
  25. #include "text/wftable.h"
  26. #include "text/ix.h"
  27.  
  28. #include "gopherd.h"
  29.  
  30. int
  31. myInterruptRoutine()
  32. {
  33.      /* for now, always return 0 so the search is not interrupted */
  34.      return(0);
  35. }
  36.  
  37. void
  38. NeXTIndexQuery(sockfd, SearchWords, ZIndexDirectory, DatabaseNm, INDEXHost, INDEXPort, INDEXPath)
  39.   int sockfd;
  40.   char *SearchWords;
  41.   char *ZIndexDirectory;
  42.   char *DatabaseNm;  /*** Not used by the next indexer... ***/
  43.   char *INDEXHost;
  44.   int INDEXPort;
  45.   char *INDEXPath;
  46. {
  47.      unsigned long i;
  48.      char *cp;
  49.      int j;
  50.      Index *workingIndex;
  51.      RefList theRefList;
  52.      RefList *ptrtheRefList;
  53.      Reference *MyReference;
  54.      FileCell *f;
  55.      char tempstr[40];
  56.      char outputline[1024];
  57.      GopherObj *gs;
  58.      GopherDirObj *gd;
  59.  
  60.      gs = GSnew();
  61.      gd = GDnew(32);
  62.  
  63.      if (DEBUG) {
  64.       printf("Nextindexer called: Search %s, Indexdir %s\n", SearchWords, ZIndexDirectory);
  65.      }
  66.  
  67.      /*** Try to open the index a couple of times ***/
  68.      for (j=0; j< 4; j++) {
  69.       workingIndex = ixOpen( ZIndexDirectory, "r" );
  70.       if (workingIndex != NULL)
  71.            break;
  72.       else
  73.            usleep (50);
  74.      }
  75.  
  76.      if ( workingIndex != 0 ) {
  77.       theRefList = ixIndexQuery(workingIndex, SearchWords, ixSearchByFullWord,
  78.                     ixMatchContent, ixLiteralString,
  79.                     (myInterruptRoutine));
  80.  
  81.       for( i=0; i < theRefList.n; i++ ){
  82.            MyReference = &(theRefList.r[i]);
  83.            f = (*MyReference).f;
  84.            
  85.            /*** The Selector String ***/
  86.            /*** So far we only index text files, so put a 0 in front ***/
  87.  
  88.            if (strstr((*f).file, ".cache") != NULL) {
  89.             continue;
  90.            }
  91.            
  92.            GSsetType(gs, '0');
  93.            /*** Process the description field, remove any crud, replace
  94.                     with spaces. ***/
  95.                {
  96.             char *moo = f->desc;
  97.             while (*moo != '\0') {
  98.                 if (!isprint(*moo))
  99.                     *moo = ' ';
  100.                 moo++;
  101.             }
  102.         }
  103.         
  104.            GSsetTitle(gs, (f->desc)+1);
  105.            GSsetHost(gs, INDEXHost);
  106.            GSsetPort(gs, INDEXPort);
  107.  
  108.            cp = strstr(f->file, INDEXPath);
  109.            if (cp == NULL)
  110.             sprintf(outputline, "0/%s", f->file);
  111.            else
  112.             sprintf(outputline, "0/%s", cp);
  113.  
  114.            if (MacIndex)
  115.             GSsetPath(gs, f->file);
  116.            else
  117.                    GSsetPath(gs, outputline);
  118.            GSsetWeight(gs, (int)(MyReference->weight * 1000.0));
  119.            GDaddGS(gd, gs);
  120.       }
  121.  
  122.       if (UsingHTML)
  123.            GDtoNetHTML(gd, sockfd);
  124.       else
  125.            GDtoNet(gd, sockfd);
  126.  
  127.       writestring(sockfd, ".\r\n");
  128.       
  129.      }
  130.      else {
  131.       fprintf(stderr,"can't open working index\n" );
  132.      }
  133.  
  134.      GSdestroy(gs);
  135.      GDdestroy(gd);
  136.      
  137.      /* all done.... close the index file */
  138. }
  139.  
  140.